home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 3.3 (Developer)…68k, x86, SPARC, PA-RISC] / NeXTSTEP 3.3 Dev Intel.iso / NextDeveloper / Headers / g++ / MLCG.h < prev    next >
C/C++ Source or Header  |  1995-02-06  |  2KB  |  95 lines

  1. // This may look like C code, but it is really -*- C++ -*-
  2. /* 
  3. Copyright (C) 1988 Free Software Foundation
  4.     written by Dirk Grunwald (grunwald@cs.uiuc.edu)
  5.  
  6. This file is part of the GNU C++ Library.  This library is free
  7. software; you can redistribute it and/or modify it under the terms of
  8. the GNU Library General Public License as published by the Free
  9. Software Foundation; either version 2 of the License, or (at your
  10. option) any later version.  This library is distributed in the hope
  11. that it will be useful, but WITHOUT ANY WARRANTY; without even the
  12. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  13. PURPOSE.  See the GNU Library General Public License for more details.
  14. You should have received a copy of the GNU Library General Public
  15. License along with this library; if not, write to the Free Software
  16. Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  17. */
  18. #ifndef _MLCG_h
  19. #define _MLCG_h 1 
  20. #ifdef __GNUG__
  21. #pragma interface
  22. #pragma cplusplus
  23. #endif
  24.  
  25. #include <RNG.h>
  26. #ifdef __cplusplus
  27. extern "C" {
  28. #endif
  29. #include <math.h>
  30. #ifdef __cplusplus
  31. }
  32. #endif
  33.  
  34. //
  35. //    Multiplicative Linear Conguential Generator
  36. //
  37.  
  38. class MLCG : public RNG {
  39.     long initialSeedOne;
  40.     long initialSeedTwo;
  41.     long seedOne;
  42.     long seedTwo;
  43.  
  44. protected:
  45.  
  46. public:
  47.     MLCG(long seed1 = 0, long seed2 = 1);
  48.     //
  49.     // Return a long-words word of random bits
  50.     //
  51.     virtual unsigned long asLong();
  52.     virtual void reset();
  53.     long seed1();
  54.     void seed1(long);
  55.     long seed2();
  56.     void seed2(long);
  57.     void reseed(long, long);
  58. };
  59.  
  60. inline long
  61. MLCG::seed1()
  62. {
  63.     return(seedOne);
  64. }
  65.  
  66. inline void
  67. MLCG::seed1(long s)
  68. {
  69.     initialSeedOne = s;
  70.     reset();
  71. }
  72.  
  73. inline long
  74. MLCG::seed2()
  75. {
  76.     return(seedTwo);
  77. }
  78.  
  79. inline void
  80. MLCG::seed2(long s)
  81. {
  82.     initialSeedTwo = s;
  83.     reset();
  84. }
  85.  
  86. inline void
  87. MLCG::reseed(long s1, long s2)
  88. {
  89.     initialSeedOne = s1;
  90.     initialSeedTwo = s2;
  91.     reset();
  92. }
  93.  
  94. #endif
  95.